﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Domain.Core.Specification;
using Domain.Entities;

namespace Domain.Service.Order
{
    /// <summary>
    /// 订单业务
    /// </summary>
    public class OrderService
    {
        IOrderRepository _iOrderRepository;
        IEmailApplication _iEmailApplication;
        public OrderService(IOrderRepository iOrderRepository, IEmailApplication iEmailApplication)
        {
            _iOrderRepository = iOrderRepository;
            _iEmailApplication = iEmailApplication;
        }
        /// <summary>
        /// 生成订单
        /// </summary>
        /// <param name="order"></param>
        public void GeneratorOrder(Order_Ext order)
        {
            //订单实体持久化
            _iOrderRepository.InsertOrder(order.OrderInfo);
            //发邮件
            _iEmailApplication.Send(new Email
            {
                Body = "下订单成功",
                Title = "下订单成功",
                To = order.User_Info.Email,
                CreateDate = DateTime.Now,
            });

        }

        /// <summary>
        /// 根据WEB层传来及组件好的规约，返回集体
        /// </summary>
        /// <param name="spec"></param>
        /// <returns></returns>
        public List<Order_Info> GetOrder_InfoBySpec(ISpecification<Order_Info> spec)
        {
            return _iOrderRepository.GetEntities(spec).ToList();
        }
    }
}
